package com.example.everying.controller.statistics;/*
 * 项目名称: everything
 * 文件名: UserBehaviorLogController
 * 作者: 张泽阳
 * 日期: 2025/7/18
 * 描述:
 */

import com.example.everying.annotation.WebLog;
import com.example.everying.constant.ActionEnum;
import com.example.everying.model.dto.statistics.ArticleStayDurationDto;
import com.example.everying.model.dto.statistics.ShareDto;
import com.example.everying.model.entity.statistics.UserBehaviorLog;
import com.example.everying.service.statistics.UserBehaviorLogService;
import com.example.everying.service.statistics.UserSessionService;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "用户行为日志")
@RequestMapping("/statistics/userBehaviorLog")
public class UserBehaviorLogController {

    @Autowired
    private UserBehaviorLogService userBehaviorLogService;

    @Autowired
    private UserSessionService userSessionService;

    @WebLog(description = "分享记录")
    @PostMapping("/shareRecord")
    public Result<?> shareRecord(@RequestBody ShareDto shareDto){
        UserBehaviorLog userBehaviorLog = new UserBehaviorLog();
        userBehaviorLog.setUserId(shareDto.getUserId());
        userBehaviorLog.setArticleId(shareDto.getArticleId());
        userBehaviorLog.setActionCode(ActionEnum.SHARE.getActionCode());
        userBehaviorLog.setActionName(ActionEnum.SHARE.getActionName());
        boolean b = userBehaviorLogService.addUserBehaviorLog(userBehaviorLog);
        if ( b){
            return Result.ok("记录成功");
        }
        return Result.ok("记录失败");
    }

    @WebLog(description = "记录帖子留存时间")
    @PostMapping("/articleStayDuration")
    public Result<?> articleStayDuration(@RequestBody ArticleStayDurationDto articleStayDurationDto){
        UserBehaviorLog userBehaviorLog = new UserBehaviorLog();
        userBehaviorLog.setUserId(articleStayDurationDto.getUserId());
        userBehaviorLog.setArticleId(articleStayDurationDto.getArticleId());
        userBehaviorLog.setStayDuration(articleStayDurationDto.getDuration());
        userBehaviorLog.setActionCode(ActionEnum.STAY.getActionCode());
        userBehaviorLog.setActionName(ActionEnum.STAY.getActionName());
        boolean b = userBehaviorLogService.addUserBehaviorLog(userBehaviorLog);
        if ( b){
            return Result.ok("记录成功");
        }
        return Result.ok("记录失败");
    }



}
